﻿using IPC.WinForm.Bussiness;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IPC.WinForm.BaseForm
{
    public partial class FrmConfig : Form
    {
        public FrmConfig()
        {
            InitializeComponent();
            TableLayoutControlCollection controlCollection = this.tableLayoutPanel1.Controls;
            foreach (Control control in controlCollection)
            {
                if (control is TextBox)
                {
                    string configKey = control.Name;
                    string defaultValue = "";
                    if(configKey == "Port")
                    {
                        defaultValue = "9099";
                    }
                    control.Text = ConfigDbBussiness.Instance.GetConfigByKey(configKey, defaultValue);
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TableLayoutControlCollection controlCollection = this.tableLayoutPanel1.Controls;
            foreach (Control control in controlCollection)
            {
                if(control is TextBox)
                {
                    string configKey = control.Name;
                    string configValue = control.Text;
                    ConfigDbBussiness.Instance.UpdateConfig(configKey, configValue);
                }
            }
            this.DialogResult = DialogResult.OK;
        }
    }
}
